//var res, raw
//raw = 5 / 3
//console.log(raw)
//res = Math.round(raw)
//console.log(res)
//res = Math.floor(raw)
//console.log(res)

var input, output;

input = 7;
test1To19()
//console.log(output.length)
//output = calLayout(output, {x: 100, y: 100})
//console.log(output)

function testA() {
    output = calMatrix(input)
    console.log(output)
}
function test1To19() {
    for (var i = 1; i < 19; i++) {
        output = calMatrix(i)
        var str = i + ' --> [ ' + output + ' ]'
        console.log(str)
    }
}


/*
 5 // 5
 6 // 3 3
 7 // 3 4
 8 // 3 2 3
 10// 3 4 3
 14// 3 4 4 3
 19// 3 4 5 4 3
 24// 3 4 5 5 4 3
 29// 3 4 5 5 5 4 3
 */
function calMatrix2(total){
    /*
     if(n<=5){
     out.push(n)
     return out;
     }else if(n>5 && n < )
     n-=6;
     out.push(3,3)
     if(n < 5 ){
     out.push(n)
     }
     n-=5;
     out.push()
     if(n < 5 ){
     out.push(n)
     }
     return out
     */
}
// 计算每行有多少个金币
function calMatrix(total) {
    if (!total) throw "input error."
    var n = total;
    var max = 5;
    var out = []

    for (var i = 0; n > 0; i++) {
        var value = (n / max >= 1) ? max : n % max;
        n -= max;
        out.push(value);
    }

    return out
}

//根据一个数组,计算每个金币的位置.输出顺序 y从大到小,x从小到大.
function calLayout(array, centerPos) {
    var w = 80, h = 80;
    var cx = centerPos.x, cy = centerPos.y;
    var _ouput = []

    var len = array.length, cenXNum, cenYNum = Math.ceil(len / 2);
    for (var i = 1; i <= len; i++) {
        var x, y, n = array[i - 1];
        var tmpY = (len % 2 == 1) ? cy : cy - h / 2;
        y = (i - cenYNum) * h + tmpY;
        cenXNum = Math.ceil(n / 2);
        var tmpX = (n % 2 == 1) ? cx : cx - w / 2;
        for (var j = n; j > 0; j--) {
            x = (j - cenXNum) * w + tmpX;
            _ouput.push({x: x, y: y});
        }
    }
    return _ouput.reverse()
}



